/**
 * Created by asus on 2017/9/25.
 */
public class Linked<T> {
        private int size;
        private Point FirstPoint;//表的头
        private Point LastPoint;//表的尾


        public Linked(){
            FirstPoint = new Point(null,null,null);//开始表头为空
            LastPoint = new Point(null,FirstPoint,null);
            FirstPoint.EndPoint=LastPoint;
        }
        class Point{
            T data;
            Point HeadPoint;
            Point EndPoint;
            Point(T data,Point headPoint,Point endPoint){
                this.data = data;
                this.HeadPoint = headPoint;
                this.EndPoint = endPoint;
            }
        };
        public int size(){
            return this.size;
        }
        public boolean isEmpty(){
            return size()==0;
        }
        public boolean add(T t){
            Point point = new Point(t,LastPoint.HeadPoint,LastPoint);
            LastPoint.HeadPoint.EndPoint = point;
            LastPoint.HeadPoint = point;
            size++;
            return true;
        }
        public void remove(int index) {
            Point point = getposition(index);
            point.HeadPoint.EndPoint = point.EndPoint;
            point.EndPoint.HeadPoint = point.HeadPoint;
            point.data = null;
            point.HeadPoint = null;
            point.EndPoint = null;
            point = null;
            size--;
        }
        public T get(int index){
            Point point = getposition(index);
            return point.data;
        }
        private Point getposition(int index){
            Point point;
            int i;
            for (i =0,point=FirstPoint.EndPoint;i<index;i++){
                point = point.EndPoint;
            }
            return point;
        }

    public static void main(String[] args) {
        Linked<Integer> mlist = new Linked<>();
        mlist.add(1);
        mlist.add(2);
        mlist.add(3);
        System.out.println(mlist.get(1));
    }
}
